home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A).zip / Nibble Volume 12, No. 01 (1991-01)(MindCraft Publishing)(Side A).po / MOUSE.CLOCK.SRC.txt < prev    next >
Text File  |  1996-12-24  |  8KB  |  402 lines

  1. **********************************
  2. * MOUSE.CLOCK Source Code        *
  3. * By John R. Vokey               *
  4. * (C) 1991 by MindCraft Publ.    *
  5. **********************************
  6. ;
  7. ;
  8. *=================================
  9. ;             Equates
  10. *=================================
  11. ;
  12. *   Set System DOS:
  13. PRODOS EQU $21 PRODOS = $21, DOS = 0
  14. ;
  15. *     Monitor:
  16. ACC EQU $45 save A loc on IRQ
  17. SAVEA EQU $FC temp for Acc
  18. SAVEX EQU SAVEA+1 temp for X reg
  19. SAVEY EQU SAVEX+1 temp for Y reg
  20. SCREEN EQU $41D 40-col screen position
  21. USER EQU $0000 User's interrupt handler
  22. ;
  23. *     Applesoft:
  24. CHKCOM EQU $DEBE Check for comma at TXTPTR
  25. PTRGET EQU $DFE3 returns variable pointer
  26. VARPNT EQU $83 Applesoft pointer
  27. ERROR EQU $D412 error routine
  28. ;
  29. *     Mouse:
  30. MSLOT EQU $C400 assume slot 4
  31. NUM EQU $FF used as a temp
  32. ;
  33. *     ProDOS:
  34. ALLOC EQU $40 allocate interrupt code
  35. MLI EQU $BF00 Machine Language Interface
  36. DATETIME EQU $BF06 Date/time jump
  37. PTIME EQU $BF92 time locations
  38. BITMAP EQU $BF58 system bit map
  39. GOSYSTEM EQU $BE70 BASIC.SYSTEM command call
  40. GETBUFR EQU $BEF5 Get Buffer
  41. ERROUT EQU $BE09 error exit
  42. ;
  43. *     DOS 3.3:
  44. BUFCNT EQU $AA57 # of buffers to create
  45. BUFPTR EQU $9D00 pointer to new buffer
  46. BUFBLD EQU $A7D4 build buffers
  47. DOSLOC EQU $9C00 relocation page
  48. ;
  49. *     Origin:
  50.  ORG $4000-$44-PRODOS
  51. ;
  52. *=================================
  53. ;            Relocate
  54. *=================================
  55. ;
  56.  DO PRODOS
  57.  LDA #1 ask BASIC.SYSTEM for 1 page
  58.  JSR GETBUFR
  59.  BCS BADERR Error
  60.  STA VARPNT+1 (for move)
  61.  PHA  save it
  62.  LSR A shift down
  63.  LSR A
  64.  LSR A
  65.  TAX  use as index into bitmap
  66.  PLA
  67.  EOR #$FF complement
  68.  AND #$7 mask off high bits
  69.  SEC
  70.  TAY
  71.  LDA #0 clear Acc
  72. PLOOP ROL A shift 'Y' times
  73.  DEY
  74.  BPL PLOOP
  75.  ORA BITMAP,X set bit
  76.  STA BITMAP,X flag "used"
  77.  LDA VARPNT+1 recover hbyte
  78.  STA P2
  79.  STA P4+1
  80. ;
  81.  ELSE
  82.  LDA #>DOSLOC lbyte of space
  83.  SEC
  84.  SBC #$26 name, pointers, etc.
  85.  STA BUFPTR
  86.  LDA #<DOSLOC hbyte
  87.  SBC #0
  88.  STA BUFPTR+1
  89.  LDA #3 set default (3) buffers
  90.  STA BUFCNT
  91.  JSR BUFBLD create space
  92.  LDA #<DOSLOC
  93.  STA D2+1
  94.  FIN
  95. ;
  96. MOVE LDY #0
  97.  STY VARPNT
  98.  STA VARPNT+1
  99. MLOOP LDA SETMOUSE,Y
  100.  STA (VARPNT),Y
  101.  DEY
  102.  BNE MLOOP
  103. ;
  104.  LDX RBYTES get # of bytes
  105.  LDA VARPNT+1 recover page #
  106. RLOOP PHA
  107.  LDA RBYTES,X get index of byte to fix
  108.  TAY  use Y as index
  109.  PLA
  110.  STA (VARPNT),Y fix it
  111.  DEX  more?
  112.  BNE RLOOP Yes, loop until done
  113. ;
  114. *=================================
  115. ;           Initialize
  116. *=================================
  117. ;
  118.  DO PRODOS
  119.  JSR MLI call command dispatcher
  120.  DFB ALLOC to install interrupt
  121.  DW PRMLST handler
  122.  BCC DOTIME
  123. BADERR JMP ERROUT exit if error
  124. PRMLST DFB 2,0
  125.  DFB >IHAND
  126. P2 DFB <IHAND
  127. ;
  128.  ELSE
  129. *     set DOS interrupts
  130.  LDA #>IHAND
  131.  STA $3FE
  132. D2 LDA #<IHAND
  133.  STA $3FF
  134.  FIN
  135. ;
  136. *     Setup ProDOS time call:
  137. DOTIME DO PRODOS
  138.  LDA #$4C a "JMP"
  139.  STA DATETIME
  140.  LDA #>SAVTIME and point to
  141.  STA DATETIME+1 time routine
  142. P4 LDA #<SAVTIME
  143.  STA DATETIME+2
  144.  FIN
  145. ;
  146. *=================================
  147. ;           Start Clock
  148. *=================================
  149. ;
  150. ; The mouse will be placed in
  151. ; TRANSPARENT mode with the vertical
  152. ; blanking signal active such that
  153. ; each VBL will result in an interrupt.
  154. ; Since VBL occurs once every 1/60 of
  155. ; a second, 3 VBLs is equivalent to
  156. ; 5 centiseconds.
  157. ;
  158. * Permanent code begins here
  159. ;
  160. SETMOUSE LDY #$19
  161. M1 JSR CALL do INITMOUSE
  162.  BCS MSEERR if error, exit
  163.  SEI Disable Interrupts
  164. ;
  165. SETMODE LDA #$9 set TRANSPARENT mode
  166. SETMDE LDY #$12 (VBLINT active)
  167. M2 JSR CALL do SETMOUSE
  168.  BCS MSEERR if error, exit
  169.  CLI enable interrupts
  170.  RTS  Done
  171. ;
  172. MSEERR LDX #$17 make "ERROR"
  173.  JMP ERROR
  174. ;
  175. *=================================
  176. ;           Kill Mouse
  177. *=================================
  178. ;
  179. ; Call this routine to turn mouse.clock
  180. ; off; call the above routine to start
  181. ; it again.
  182. ;
  183. KILLMSE SEI turn off interrupts
  184.  LDA #0 mouse off
  185.  BEQ SETMDE do SETMOUSE, exit
  186. ;
  187. *=================================
  188. ;           Call Mouse
  189. *=================================
  190. ;
  191. ; Input: A - mode (if any)
  192. ;        Y - offset to command call
  193. ;          - assumes mouse in MSLOT
  194. ; Output: X, Y, A scrambled
  195. ;
  196. CALL PHA save mode 
  197.  LDA MSLOT,Y get low byte
  198. R1 STA DOIT+1 self-modifying code
  199.  LDX #<MSLOT X, Y housekeeping
  200.  LDY #<MSLOT-$C000*$10
  201.  PLA recover mode
  202. DOIT JMP MSLOT do mouse call, exit
  203. ;
  204. *=================================
  205. ;         Interrupt Handler
  206. *=================================
  207. ;
  208. IHAND CLD ProDOS wants this
  209.  LDA $45 save regs for old monitors
  210.  STA SAVEA
  211.  STX SAVEX
  212.  STY SAVEY
  213.  LDY #$13 Who interrupted?
  214. R2 JSR CALL do SERVEMOUSE
  215.  BCS EXIT Not mouse, so go
  216.  SEI Mouse, so disable interrupts
  217. ;
  218. *=================================
  219. ;     Function: TIME$
  220. *=================================
  221. ;
  222. ; This routine adds a TIME$ function
  223. ; to Applesoft BASIC.  On every
  224. ; 3 vertical blanks, the time count for
  225. ; CSECS, SECS, MINS, and HOUR is updated.
  226. ; The time is then converted to its
  227. ; ASCII equivalent in a HH:MM:SS CS
  228. ; format and stored in OUTSTR.
  229. ; If screen display is selected
  230. ; (DSPTGL = TRUE), OUTSTR is output
  231. ; to the screen at SCREEN.
  232. ;
  233. TIMER DEC TIMECNT count 3 cycles
  234.  BNE EXIT If not 0, go
  235.  LDY #3 reset cycle count
  236. T1 STY TIMECNT
  237.  LDA #5 increment msecs
  238. TLOOP ADC TIME,Y increment counter
  239.  CMP TIMLIM,Y counter done?
  240.  STA TIME,Y
  241.  LDA #0
  242.  BCC NXTCNT no, next counter
  243. T2 STA TIME,Y yes, clear it
  244. NXTCNT DEY next counter, please
  245.  BPL TLOOP and go again
  246. ;
  247. F1 LDA TIME get hours
  248.  BNE TIMEOUT if not 0, go
  249. F2 LDA TIMLIM get clock type
  250.  CMP #24 24-hour clock?
  251.  BEQ TIMEOUT yes, go
  252. F3 INC TIME make hours = 1
  253. ;
  254. TIMEOUT LDX #0 Init OUTSTR ptr
  255.  LDY #0 start with hours
  256. TOUTLP TYA save Y
  257.  PHA on stack
  258. T3 LDA TIME,Y get time count
  259.  STA NUM save number
  260.  LDY #1 init to 10^1
  261. INLOOP LDA #0 assume zero
  262.  PHA save it
  263. LOOP LDA NUM recover number
  264. T4 CMP POFTEN,Y >= 10^Y?
  265.  BCC NUMOUT No, done
  266. T5 SBC POFTEN,Y Yes, divide by subtraction
  267.  STA NUM save remainder
  268.  PLA count divisions
  269.  SEC add 1 to Acc
  270.  ADC #0
  271.  PHA save again
  272.  BCC LOOP always taken
  273. NUMOUT PLA recover digit (0-9)
  274.  ORA #$30 ASCII "0" + digit
  275. T6 STA OUTSTR,X save ASCII equivalent
  276.  INX next output loc
  277.  DEY next digit
  278.  BPL INLOOP
  279.  INX skip delimiter
  280.  PLA recover Y
  281.  TAY
  282.  INY
  283.  CPY #4 All done?
  284.  BCC TOUTLP No, go again
  285. S1 LDA DSPTGL Yes, display to screen?
  286.  BEQ ALLDONE No, go
  287.  LDY #10 else, 11 chars to go
  288. S2 LDA OUTSTR,Y get char
  289.  STA SCREEN,Y store to screen
  290.  DEY
  291.  BPL S2
  292. ALLDONE CLC mark successful call
  293. ;
  294. *=================================
  295. ;              Exit
  296. *=================================
  297. ;
  298. EXIT DO USER
  299.  JSR USER do User's handler
  300.  ELSE
  301.  NOP
  302.  NOP
  303.  NOP
  304.  FIN
  305. ;
  306.  LDA SAVEA recover regs
  307.  STA $45 how we were called...
  308.  LDX SAVEX
  309.  LDY SAVEY
  310. ;
  311.  DO PRODOS
  312.  NOP keeps offsets equal
  313.  RTS
  314. ;
  315.  ELSE
  316.  CLI for DOS
  317.  RTI
  318.  FIN
  319. ;
  320. *=================================
  321. ;       Internal variables
  322. *=================================
  323. ;
  324. TIMECNT DFB 3
  325. DSPTGL DFB 0 init to off
  326. TIME DFB 0,0,0,0
  327. TIMLIM DFB 24,60,60,100
  328. POFTEN DFB 1,10
  329.  MSB OFF
  330. OUTSTR ASC '00:00:00 00'
  331. PTR DFB 11,>OUTSTR,<OUTSTR
  332. ;
  333. *=================================
  334. ;Assign OUTSTR to user's variable:
  335. *=================================
  336. ;
  337. ; Points the user's string variable
  338. ; at OUTSTR.  From BASIC:
  339. ; LET ASSIGN = Address
  340. ; CALL ASSIGN,TIME$
  341. ; Then PRINT TIME$ will return
  342. ; the current time.  The value of TIME$
  343. ; will automatically be updated.
  344. ;
  345. ASSIGN JSR CHKCOM check for comma
  346.  JSR PTRGET locate variable
  347.  LDY #2 offset to pointer
  348. ALOOP LDA PTR,Y
  349.  STA (VARPNT),Y
  350.  DEY
  351.  BPL ALOOP
  352.  RTS
  353. ;
  354. *=================================
  355. ;          Display Switch
  356. *=================================
  357. ;
  358. ; Calling this routine toggles
  359. ; screen display on/off.
  360. ;
  361. DISPSWCH LDA DSPTGL get value
  362.  EOR #$FF toggle
  363. S3 STA DSPTGL
  364.  RTS exit
  365. ;
  366. *=================================
  367. ;         ProDOS TIME call
  368. *=================================
  369. ;
  370. ; Updates the ProDOS time locations
  371. ; when called by the MLI.
  372. ;
  373. SAVTIME DO PRODOS
  374. P5 LDA TIME+1
  375.  STA PTIME
  376. P6 LDA TIME
  377.  STA PTIME+1
  378.  RTS
  379.  FIN
  380. ;
  381. *=================================
  382. ;       Relocation Bytes
  383. *=================================
  384. ;
  385. RBYTES DO PRODOS
  386.  DFB 25
  387. ;
  388.  ELSE
  389.  DFB 23
  390.  FIN
  391. ;
  392.  DFB M1+2,M2+2
  393.  DFB R1+2,R2+2,TIMER+2,T1+2
  394.  DFB TLOOP+2,TLOOP+5,TLOOP+8
  395.  DFB T2+2,F1+2,F2+2,F3+2,T3+2,T4+2,T5+2,T6+2
  396.  DFB S1+2,S2+2,PTR+2
  397.  DFB ALOOP+2,DISPSWCH+2,S3+2
  398. ;
  399.  DO PRODOS
  400.  DFB P5+2,P6+2
  401.  FIN
  402.